package com.wontube.smr.bo.sites.hulu;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.wontube.client.extension.utils.ArrayUtils;
import com.wontube.client.extension.utils.StringUtils;
import com.wontube.smr.bo.constants.StandarTVGenres;

/**
 * @author tanggf(2012-8-4)
 *
 */
public class HuluTVGenres {
	private HuluTVGenres(){}
	
	//private static final Map<String, String> siteStandarMap = new HashMap<String, String>();		
	private static final Map<String, String> map = new HashMap<String, String>();	
	
	static {
		//loadTVGenersMap();
		
		//Action and Adventure, 
		map.put("Action and Adventure", StandarTVGenres.ACTION);
		map.put("Animation and Cartoons", StandarTVGenres.ANIMATION);
		map.put("Arts and Culture", StandarTVGenres.CULTURE);
		//map.put("Foreign Language", StandarTVGenres.FOREIGN);
		map.put("Horror and Suspense", StandarTVGenres.HORROR);
		map.put("Science Fiction", StandarTVGenres.SCIENCE);
		map.put("Food and Leisure", StandarTVGenres.FOOD);
		map.put("Health and Wellness", StandarTVGenres.HEALTH);
		map.put("News and Information", StandarTVGenres.NEWS);
		map.put("Reality and Game Shows", StandarTVGenres.GAME);
		//map.put("Talk and Interview", StandarTVGenres.TALK);
		map.put("Arts and Culture", StandarTVGenres.CULTURE);		
		map.put("Gay and Lesbian", StandarTVGenres.GAY_AND_LESBIAN);
		//map.put("Home and Garden", StandarTVGenres.HOME);
		map.put("Korean Drama", StandarTVGenres.KOREAN_DRAMA);				
		map.put("Documentaries", StandarTVGenres.Documentary);
	}
	
	/*
	private static void loadTVGenersMap(){
		List<GenreSite> genreSites = GenreSelectDao.selectGenreSites(SiteConstants.WEBSITE_HULU, 
				Genre.CATE_TV);
		for (GenreSite gs : genreSites) {
			siteStandarMap.put(gs.getSiteGenre(), gs.getStandarGenre());
		}
	}
	*/
	/**
	 * 修正单个genre
	 * @param genreName
	 * @return
	 */
	public static String remendGenre(String genreName){
		if(StringUtils.isNullOrEmpty(genreName)){
			return null;
		}
		
		//处理专有genre
		String genre = map.get(genreName);
		if(genre == null){
			//不存在则判断是标准genre
			return genreName;
		}
		return genre;
	}
	
	/**
	 * 修正以逗号分隔的genres
	 * @param genreNames
	 * @return
	 */
	public static String remendAllGenres(String genreNames){
		if(StringUtils.isNullOrEmpty(genreNames)){
			return null;
		}
		
		Set<String> genreSet = new HashSet<String>();
		
		String[] genres = genreNames.split("\\s*,\\s*");
		for (String g : genres) {
			String rg = remendGenre(g);
			if(rg != null){
				genreSet.add(rg);
			}		
		}
		
		return ArrayUtils.join(genreSet, ",");
	}
}
